package com.xiashitech.agent.instrumentation.db.statement;

import io.opentelemetry.javaagent.shaded.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.javaagent.shaded.instrumentation.jdbc.internal.DbRequest;
import io.opentelemetry.javaagent.shaded.instrumentation.jdbc.internal.JdbcAttributesGetter;
import io.opentelemetry.javaagent.shaded.io.opentelemetry.api.GlobalOpenTelemetry;

public class XSJdbcSingletons {

    private XSJdbcSingletons() {}

    private static final String INSTRUMENTATION_NAME = "com.xiashitech.jdbc";

    private static final Instrumenter<DbRequest, Void> INSTRUMENTER;

    public static Instrumenter<DbRequest, Void> jdbcInstrumenter() {
        return INSTRUMENTER;
    }

    static {
        JdbcAttributesGetter dbAttributesGetter = new JdbcAttributesGetter();
        INSTRUMENTER =
                Instrumenter.<DbRequest, Void>builder(
                                GlobalOpenTelemetry.get(),
                                INSTRUMENTATION_NAME,
                                XSJdbcSpanNameExtractor.create(dbAttributesGetter))
                        .addAttributesExtractor(XSJdbcAttributesExtractor.create(dbAttributesGetter))
                        .buildInstrumenter();
    }
}
